var getColor=function(a)
{
	if(a==0)
	{
			return "red";
	}else
	{
			return "green";
	}
}
function showPoly(a,b) {
	//去掉点击某个点弹出东西
for (var c = 0; c < a.data.length; c++) {
			var adlength=a.data[c].length;
			var posistionarr=[];
			for(var c1=0;c1<adlength;c1++)
			{
				var point=new BMap.Point(a.data[c][c1].x, a.data[c][c1].y);
				var i = new BMap.Marker(point);
			//	i.setIcon("images/deskicon.ico");
				i.setIcon(new BMap.Icon("http://www.crazyflasher.com/favicon.ico",new BMap.Size(16,16)));
				b.addOverlay(i);
				posistionarr.push(point);
				consoles(i,a.data[c][c1]);
			}
			posistionarr.push(posistionarr[0]);
			lines(posistionarr,b, a.data[c][0].taskType);
	}
}

function consoles(i,task)
{
	var k = new BMap.Label("xxx"+task.taskid, {
		//距离点的左右位置和上下位置
	offset: new BMap.Size(20, -10)
	});
	k.setContent("<div style='width:100px;height:30px;'><img src='images/favicon.ico'>"+task.taskName+"-"+task.cmName+"</div>");
	 k.setStyle({ 
			color: "red", 
			border: "0px", 
			backgroundColor: "0.000000000001",  //通过这个方法，去掉背景色 
			fontSize: "16px", 
			height: "20px", 
			lineHeight: "20px" 
		}); 
	k.setTitle("标题");
	k.addEventListener("click", function(){alert(this.getPosition().lng+","+this.getPosition().lat)});
	i.setLabel(k)
}

//划线
function lines(posistionarr,b,type)
{
   // var driving2 = new BMap.DrivingRoute(b, {renderOptions:{map: b, autoViewport: true}});    //驾车实例
  //  driving2.search(posistionarr[0], posistionarr[1]);    //显示一条公交线路

	if(1==1){
	var e = Math.floor(posistionarr.length / 11);
			var f = posistionarr.length % 11;
			var g = new BMap.DrivingRoute(b, {
			onSearchComplete: function(i) {
					if (g.getStatus() == BMAP_STATUS_SUCCESS) {
							var j = g.getResults().getPlan(0);
							var k = j.getNumRoutes();
								for (var l = 0; l < k; l++) {
								var m = j.getRoute(l).getPath();
								var n = new BMap.Polyline(m);
								var o = getColor(type);
								n.setStrokeColor(o);
								//线的粗细
								n.setStrokeWeight(4);
								b.addOverlay(n)
								}
							}
					}
			});
			for (var h = 0; h < e; h++) {
				var i = posistionarr.slice(h * 11 + 1, (h + 1) * 11);
				g.search(posistionarr[h * 11], posistionarr[(h + 1) * 11 - 1], {
				waypoints: i
				})
			};
			if (f != 0) {
					var i = posistionarr.slice(e * 11, posistionarr.length - 1);
					g.search(posistionarr[e * 11], posistionarr[posistionarr.length - 1], {
					waypoints: i
				})
			}
	}
}